import React, { Component } from 'react';
import './index.css';

export default class Footer extends Component {
  render() {
    const doneCount = this.props.todos.reduce((accur, cur) => accur + (cur.done ? 1 : 0), 0);
    return (
      <div className='footer'>
        <input
          type='checkbox'
          checked={doneCount === this.props.todos.length && doneCount}
          onChange={this.onChange}
        />
        <span className='completeInfo'>
          已完成{doneCount} / 全部{this.props.todos.length}
        </span>
        <span className='delAll' onClick={this.delAllCompleteTask}>
          清除已完成任务
        </span>
      </div>
    );
  }
  delAllCompleteTask = () => {
    this.props.delAllCompleteTask();
  };
  onChange = e => {
    this.props.handleAllChange(e.target.checked);
  };
}
